﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jenvin.Library.Helper;
using Jenvin.Library.DataStruct;
using Jenvin.Library.Functional;
using Jenvin.Library.Threading;
using System.Threading;
using System.IO;
namespace Test
{
    class Program
    {
        public class DownUrlTask : AbstractTask
        {
            public string Msg { get; set; }
            public override void Execute()
            {
                Thread.Sleep(1000);
                Console.WriteLine(Msg);
            }
        }
        public class CountTask : AbstractTask
        {
            public int Count { get; set; }

            public override void Execute()
            {
                if (Count == -1)
                {
                    this.Context.Exited = true;
                    Console.WriteLine(this.Context.Params);
                }
                this.Context.Params = (int)this.Context.Params + Count;
            }
        }
        static void Main(string[] args)
        {
          
          
            //var sum1 = File.ReadAllLines(@"C:\Documents and Settings\jenvin\桌面\1.txt")
            //    .Select(x => double.Parse(x.Trim()))
            //    .Sum();

            //var sum2 = File.ReadAllLines(@"C:\Documents and Settings\jenvin\桌面\2.txt")
            //     .Select(x => double.Parse(x.Trim()))
            //    .Sum();

            //var sum3 = File.ReadAllLines(@"C:\Documents and Settings\jenvin\桌面\3.txt")
            //    .Select(x => double.Parse(x.Trim()))
            //    .Sum();

            //var sum = sum1 + sum2 + sum3;
            //var day = (DateTime.Now - new DateTime(2011, 3, 7)).Days;

            //var day1 = 20;//周未 3.17 - 5.30
            //var day2 = day - day1;

            //var per = sum / day;

            //var total1 = per * day1;
            //var total2 = per * day2;

            //var sister = total1 / 3 + total2 / 5;
            //var my = total1 / 3 + (total2 / 5) * 2;

            //var sistermoney = sum1 - sister;
            //var wifemoney = sum2 - my;
            //var mymoney = sum3 - my;

            //return;

            //TaskContext context = new TaskContext();

            //TaskActor actor = new TaskActor(context);
            //actor.Post(new DownUrlTask() { Msg = "1" });
            //actor.Post(new DownUrlTask() { Msg = "2" });
            //actor.Post(new DownUrlTask() { Msg = "3" });
            //actor.Post(new ExitTask());

            //TaskContext context1 = new TaskContext();
            //TaskActor actor1 = new TaskActor(context1);
            //actor1.Post(new DownUrlTask() { Msg = "4" });
            //actor1.Post(new DownUrlTask() { Msg = "5" });
            //actor1.Post(new DownUrlTask() { Msg = "6" });
            //actor1.Post(new ExitTask());

            //context.WaitForExit();
            //context1.WaitForExit();

            //TaskContext context2 = new TaskContext();
            //context2.Params = 0;
            //TaskActor actor2 = new TaskActor(context2);
            //for (int i = 0; i < 10000; i++)
            //{
            //    actor2.Post(new CountTask() { Count = i });
            //}
            //actor2.Post(new CountTask() { Count = -1 });
            //context2.WaitForExit();

            ////Thread.Sleep(200);
            //return;
            // Console.Read();

        
            PriorityQueue<int> queue= new PriorityQueue<int>(10);

           
            Random random = new Random(Guid.NewGuid().GetHashCode());

            for (int i = 0; i < 100; i++)
            {
                queue.Push(random.Next(0, 1000));
            }

            for (int i = 0; i < 10; i++)
            {
                Console.Write(queue.Pop() + " ");
            }
            Console.WriteLine();
            Console.WriteLine("////////////////////////////////////////////////");

            PriorityQueue<CacheEntry> queue2 =
                new PriorityQueue<CacheEntry>(10, (x, y) =>
                {
                    return x.acceccCount - y.acceccCount;                     
                });


            CacheEntry entry1 = new CacheEntry();
            entry1.acceccCount = 1;
            CacheEntry entry2 = new CacheEntry();
            entry2.acceccCount = 2;
            entry2.lastAccessTime = DateTime.Now;

            CacheEntry entry3 = new CacheEntry();
            entry3.acceccCount = 2;
            entry3.lastAccessTime = DateTime.Now.AddDays(-1);

            CacheEntry entry4 = new CacheEntry();
            entry4.acceccCount = 2;
            entry4.lastAccessTime = DateTime.Now.AddDays(-1);
            //IntWraper intWrapper = queue2.Top();
            queue2.Push(entry1);
            queue2.Push(entry2);
            queue2.Push(entry3);
            queue2.Push(entry4);

            for (int i = queue2.Size(); i > 0; i--)
            {
                CacheEntry c = queue2.Pop();
                Console.WriteLine(c.acceccCount + " " + c.lastAccessTime);
            }


            Console.WriteLine();
            Console.Read();
        }
    }
}
